﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Windows.Data;
using myWindowsMediaPlayer.Model;
using System.Windows.Input;

namespace myWindowsMediaPlayer.ViewModel
{
    class masterPictureViewModel : viewModelBase
    {
        private databasePicture db;
        private ObservableCollection<pictureViewModel> pictures;
        private ICollectionView collectionview;
        private masterReadChoiceViewModel choiceList;
        private ICommand addInCurrentList;

        public masterPictureViewModel(masterReadChoiceViewModel choiceList)
        {
            this.db = new databasePicture();
            pictures = new ObservableCollection<pictureViewModel>();
            foreach (pictureModel picture in db.Pictures)
                this.pictures.Add(new pictureViewModel(picture));
            this.collectionview = CollectionViewSource.GetDefaultView(this.pictures);
            this.choiceList = choiceList;
        }

        public ICommand AddInCurrentList
        {
            get
            {
                if (this.addInCurrentList == null)
                    addInCurrentList = new relayCommand(() => this.AddInList());
                return addInCurrentList;
            }
        }

        public void AddInList()
        {
            if (choiceList.Medias.Contains(new libraryViewModel(this.collectionview.CurrentItem as pictureViewModel)) != true)
                choiceList.Medias.Add(new libraryViewModel(this.collectionview.CurrentItem as pictureViewModel));
        }

        public ObservableCollection<pictureViewModel> Pictures
        {
            get { return this.pictures; }
        }

        public pictureViewModel SelectedPicture
        {
            get { return this.collectionview.CurrentItem as pictureViewModel; }
        }
    }
}
